/*************************************************
 *FileName:      wlecome.js
 *Description:   欢迎回来.js
 *Others:        陈灿
 *************************************************/
    /*
     * 启动
     */
    
    /*
     * 变量初始化
     */
    /*
     * 主程序
     */ 
    $(document).ready(function() 
    {
        //样式加载
        pagecss();
    });
    /**
     * pagecss
     * 样式加载
     * @cc 
     * @DateTime 2018-01-08T06:19:16+0800
     * @param    int        
     * @return   void
     */

    var uid = '';
    var token = '';
    var first = '';
    var second = '';

    if(localStorage.replace_uid){
        uid = localStorage.replace_uid;
    }
    if(localStorage.replace_token){
        token = localStorage.replace_token;
    }

    function pagecss(){
        if(!localStorage.replace_token || !localStorage.replace_uid){
            common.pageTransition("login.html");
        }
        $('.alink').on('tap',function(){
            common.pageTransition("forgetpsd.html");
        })
    }


    (function($, doc,$$) {
        $.init();
        var holder = doc.querySelector('#holder'),
            alert = doc.querySelector('#alert'),
            record = [];
        //处理事件
        holder.addEventListener('done', function(event) {
            var rs = event.detail;
            if(doc.querySelector('.ResetGestureCode1') !=null ){
                if (rs.points.join('')==doc.querySelector('.ResetGestureCode1')) {
                    mui.toast('密码正确');
                    record = [];
                    rs.sender.clear();
                    window.location="index.html";
                }else{
                    mui.toast('密码错误');
                    record = [];
                    rs.sender.clear();
                    return;
                }
            }else{
                if (rs.points.length < 4) {
                    rcode2text.text('设定的手势太简单了').addClass('color');
                    record = [];
                    rs.sender.clear();
                    return;
                }
                record.push(rs.points.join(''));
                if (record.length >= 2) {
                    if (record[0] == record[1]) {
                        $$.ajax({
                            type: "post",
                            url: DOMAIN_NAME + "/index.php/api/user/turesPasswordReset",
                            dataType:'jsonp',
                            data: { uid: uid, token: token, gestures_password: record[1]},
                            success: function(data) {
                                if(data.error_code == 0){
                                    mui.toast('手势设定成功');
                                    record = [];
                                    rs.sender.clear();
                                    setTimeout(function(){
                                        common.pageTransition("index.html");
                                    },1000);
                                    
                                    // window.location="index.html";
                                }else{
                                    mui.toast('密码错误');
                                    record = [];
                                    rs.sender.clear();
                                    return;
                                }
                                
                            }
                        })
                    } else {
                        rcode2text.text('两次设置不一样，请重新设置').addClass('color');
                    }
                    rs.sender.clear();
                    record = [];
                }else{
                    rcode2text.text('请确认手势设定').removeClass('color');
                    rs.sender.clear();
                }
            }
            
            console.log(rs.points.join(''));
            
        });
    }(mui, document,jQuery));

    /**
     * adds //方法名
     * @陈灿 //作者名
     * @DateTime 2018-01-010T0116:25:00+0800 //时间
     * @param    int    $goods_id //参数
     * @param    array  $data //参数
     * @return    array  [error_code, error_msg, goods_id] //返回值
     */
